package com.example.JavaWebApi.core.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

@Component
@Conditional(value = {MqttCondition.class})
@Slf4j
public class MqttConsumerCallBack1 extends AbstractMqttCallBack {
    public MqttConsumerCallBack1(MqttConfig config) {
        super(config);
    }

    /**
     * 消息到达的回调
     */
    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        log.info("接收消息主题1:{}",topic);
        log.info("接收消息Qos1:{}",message.getQos());
        log.info("接收消息内容1:{}",new String(message.getPayload()));
        log.info("接收消息retained1:{}",message.isRetained());
    }

    /**
     * 消息接收成功的回调
     */
    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        log.info("接收消息成功1");
    }
}
